<template>
  <li>
    <label>
      <input type="checkbox" @change="upDateTodoDone($event)" v-model="todo.complete" />
      <span>{{ todo.title }}</span>
    </label>
    <i @click="deleteItem" class="fa fa-trash-o fa-2x delete" title="删除"></i>
  </li>
</template>

<script>
export default {
  props: {
    todo: Object,
    index: Number,
    deleteTodo: Function,
    updateTodo: Function
  },
  methods: {
    deleteItem() {
      const todoId = this.todo._id
      this.deleteTodo(todoId, this.index)
    },
    upDateTodoDone(event) {
      const state = event.target.checked
      this.todo.complete = state
      const todoId = this.todo._id
      this.updateTodo(todoId, state)
      console.log(this.todo)
    }
  }
}
</script>

<style lang="less" scoped>
* {
  box-sizing: border-box;
}
li {
  display: flex;
  align-items: center;
  list-style: none;
  width: 100%;
  height: 40px;
  border-radius: 4px;
  transition: 0.3s;
  margin: 10px 0;
  padding: 0 10px 0 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.1);
  label {
    flex: 1;
    font-size: 16px;
  }
  input {
    vertical-align: middle;
    position: relative;
    top: -2px;
    width: 20px;
    height: 20px;
    margin-right: 10px;
    color: #2f3542;
  }
  .delete {
    padding: 4px;
    color: #2f3542;
    transition: 0.2s;
  }
  .delete:hover {
    color: #ff4757;
  }
}
li:hover {
  background-color: #ecf0f1;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1), 0 3px 8px rgba(0, 0, 0, 0.1);
}
</style>
